let path = require("path");
const { VueLoaderPlugin } = require("vue-loader/dist/index");
let nodeExternals = require("webpack-node-externals");

module.exports = {
  // Webpack 打包的目标环境为 Node.js
  target: "node",
  mode: "development",
  entry: "./src/server.js",
  output: {
    path: path.resolve(__dirname, "../build/server"),
    filename: "server_bundle.js",
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          "vue-style-loader", // 将 CSS 注入到 DOM 中
          "css-loader", // 将 CSS 转换为 CommonJS 模块
          "sass-loader",
        ],
      },
      {
        test: /\.js$/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"],
          },
        },
      },
      {
        test: /\.vue$/,
        loader: "vue-loader",
        options: {},
      },
    ],
  },
  plugins: [new VueLoaderPlugin()],
  resolve: {
    extensions: [".js", ".json", ".wasm", ".jsx", ".vue"],
  },
  // 排除 node_modules 目录下的所有模块
  externals: [nodeExternals()],
};
